//---------------------------------------------------------------------------------
// Copyright (c) 2011, Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------------

namespace Microsoft.Samples.ServiceBus.SilverlightChat.Models.ViewModels
{
    using System;
    using System.Windows;
    using Microsoft.Samples.ServiceBus.SilverlightChat.Models.Commands;

    /// <summary>
    /// Encapsulates the view model for the chat window (which contains a list of
    /// topics and their subscription statuses plus a list of received messages and
    /// a text box to type a new message into)
    /// </summary>
    public class ChatWindowViewModel : DependencyObject
    {
        public static readonly DependencyProperty CurrentTopicProperty =
            DependencyProperty.Register("CurrentTopic", typeof(ChatTopicViewModel), typeof(ChatWindowViewModel), new PropertyMetadata(null));

        private readonly ChatTopicListViewModel topics = new ChatTopicListViewModel();
        private readonly ChatWindow window;
        private readonly ChatMessageViewModel currentMessage;

        private readonly AddTopicCommand addTopicCommand;
        private readonly SendMessageCommand sendMessageCommand;

        public ChatWindowViewModel(ChatWindow window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            this.window = window;
            this.currentMessage = new ChatMessageViewModel(App.Context.UserName, string.Empty);

            this.addTopicCommand = new AddTopicCommand(this);
            this.sendMessageCommand = new SendMessageCommand(this);
        }

        public ChatWindow Window
        {
            get { return this.window; }
        }

        public AddTopicCommand AddTopicCommand
        {
            get { return this.addTopicCommand; }
        }

        public SendMessageCommand SendMessageCommand
        {
            get { return this.sendMessageCommand; }
        }

        public ChatTopicViewModel CurrentTopic
        {
            get { return (ChatTopicViewModel)GetValue(CurrentTopicProperty); }
            set { SetValue(CurrentTopicProperty, value); }
        }

        public ChatMessageViewModel CurrentMessage
        {
            get { return this.currentMessage; }
        }

        public ChatTopicListViewModel Topics
        {
            get { return this.topics; }
        }
    }
}
